<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>文件上传</title>
<script src="__PUBLIC__/Js/jquery-1.7.2.min.js"></script>
</head>

<body>
<script>
    function selectFile(rewrite){
		if(rewrite == 0){
			$('#input-write').remove();
		}else{
			$('#btn-selectFile').after('<input type="hidden" id="input-write" name="rewrite" value="'+rewrite+'">');
		}
		$('#file').click();
	}
	$(document).ready(function(e) {
        var rewrite = $(window.parent.document).find("input[name='{$name}']").val();
		if(rewrite != ''){
			$('#btn-selectFile').after('<input onClick="selectFile(\''+rewrite+'\');" type="button" value="覆盖上传">');
		}
    });
	function upload(){
		$(window.parent.document).find("input[name='{$name}']").parent().find('#{$name}').attr('src','__PUBLIC__/images/loading.jpg');
		$('#fileform').submit();
	}
</script>
<form id="fileform" action="{:U('upload')}" method="post" enctype="multipart/form-data">
    <input id="btn-selectFile" onClick="selectFile(0);" type="button" value="选择文件">
    <br>
    <br>
    <input type="hidden" name="name" value="{$name}">
    <input onChange="upload();" id="file" name="file" type="file">
</form>

</body>
</html>
